home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / basic / _Int.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  1.3 KB  |  57 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  _Int.c
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. /*         Int.cc             */
  16.  
  17. /**************************************************************************
  18.     Aufbau der Int arithmetic in C++,
  19.  
  20.     RD, IWR Uni Heidelberg, 14.12.90
  21. *****************************************************************************/
  22.  
  23.  
  24. #include <LEDA/Int0.h>
  25. #include <ctype.h>
  26.  
  27.  
  28. ostream& operator<<(ostream &out, const Int &a)
  29.     {     int l=Ilog(a)+1;
  30.         char *s=new char[l/3+2];
  31.         Itoa(a, s);
  32.         out<<s;
  33.         delete s;
  34.         return out;
  35.     }
  36.  
  37. istream& operator>>(istream &in, Int &a)
  38.     {    char s[IN_INT_BUF_LENGTH];
  39.                 char* p = s;
  40.                 char c;
  41.                 do {
  42.                   in.get(c);
  43.                   if ((c == '+') || (c == '-')) { *p++ = c; }
  44.                 } while (isspace(c) || (c == '+') || (c == '-'));
  45.                 if (!isdigit(c)) { error_handler(1,"digit expected"); }
  46.                 while (isdigit(c)) {
  47.                   *p++ = c;
  48.                   in.get(c);
  49.                 }
  50.                 in.putback(c);
  51.                 *p = '\0';
  52.         atoI(s, a);
  53.         return in;
  54.     }
  55.  
  56.